/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bs;

import com.bs.Views.AgenciaBancoView;
import com.bs.Views.BancosView;
import com.bs.Views.CEPView;
import com.bs.Views.CidadesView;
import com.bs.Views.ColaboradorView;
import com.bs.Views.EmpresaView;
import com.bs.Views.EstadoView;
import com.bs.Views.IndiceEconomicoView;
import com.bs.Views.OperadoraCartaoView;
import com.bs.Views.PaisView;
import com.bs.Views.SetorView;
import com.bs.Views.UnidadeView;
import com.bs.Views.cfopView;

/**
 *
 * @author Bone
 */
public class Inicial extends javax.swing.JFrame {

    /**
     * Creates new form Inicial
     */
    public Inicial() {
        initComponents();
        this.setExtendedState(MAXIMIZED_BOTH);
        container.removeAll();
        container.add("Empresas", new EmpresaView(container, entityManager));

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        entityManager = new com.bs.persistencia.EntityManager();
        jSplitPane1 = new javax.swing.JSplitPane();
        telasAbertas = new javax.swing.JPanel();
        container = new javax.swing.JPanel();
        jMenuBar1 = new javax.swing.JMenuBar();
        cadastrosMenu = new javax.swing.JMenu();
        cadastrosPreMenu = new javax.swing.JMenu();
        paisMenu = new javax.swing.JMenuItem();
        estadosMenu = new javax.swing.JMenuItem();
        cidadesMenu = new javax.swing.JMenuItem();
        bancosMenu = new javax.swing.JMenuItem();
        agenciaBanco = new javax.swing.JMenuItem();
        cepMenu = new javax.swing.JMenuItem();
        indicesEconomicosMenu = new javax.swing.JMenuItem();
        cfopMenu = new javax.swing.JMenuItem();
        operadoraCartaoMenu = new javax.swing.JMenuItem();
        cadastrosBasicosMenu = new javax.swing.JMenu();
        setoresMenu = new javax.swing.JMenuItem();
        colaboradoresMenu = new javax.swing.JMenuItem();
        unidadesMenu = new javax.swing.JMenuItem();
        selecionarEmpresa = new javax.swing.JMenuItem();
        relatoriosMenu = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jSplitPane1.setDividerLocation(200);

        telasAbertas.setMaximumSize(new java.awt.Dimension(1, 1));
        telasAbertas.setMinimumSize(new java.awt.Dimension(1, 1));
        telasAbertas.setPreferredSize(new java.awt.Dimension(1, 1));
        jSplitPane1.setLeftComponent(telasAbertas);

        container.setLayout(new java.awt.CardLayout());
        jSplitPane1.setRightComponent(container);

        cadastrosMenu.setText("Cadastros");

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, entityManager, org.jdesktop.beansbinding.ELProperty.create("${empresa != null}"), cadastrosMenu, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        cadastrosPreMenu.setText("Cadastros pré-existentes");

        paisMenu.setText("País");
        paisMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                paisMenuActionPerformed(evt);
            }
        });
        cadastrosPreMenu.add(paisMenu);

        estadosMenu.setText("Estados");
        estadosMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                estadosMenuActionPerformed(evt);
            }
        });
        cadastrosPreMenu.add(estadosMenu);

        cidadesMenu.setText("Cidades");
        cidadesMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cidadesMenuActionPerformed(evt);
            }
        });
        cadastrosPreMenu.add(cidadesMenu);

        bancosMenu.setText("Bancos");
        bancosMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bancosMenuActionPerformed(evt);
            }
        });
        cadastrosPreMenu.add(bancosMenu);

        agenciaBanco.setText("Agências bancárias");
        agenciaBanco.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                agenciaBancoActionPerformed(evt);
            }
        });
        cadastrosPreMenu.add(agenciaBanco);

        cepMenu.setText("CEPs");
        cepMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cepMenuActionPerformed(evt);
            }
        });
        cadastrosPreMenu.add(cepMenu);

        indicesEconomicosMenu.setText("Indices econômicos");
        indicesEconomicosMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                indicesEconomicosMenuActionPerformed(evt);
            }
        });
        cadastrosPreMenu.add(indicesEconomicosMenu);

        cfopMenu.setText("CFOP");
        cfopMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cfopMenuActionPerformed(evt);
            }
        });
        cadastrosPreMenu.add(cfopMenu);

        operadoraCartaoMenu.setText("Operadoras de cartão");
        operadoraCartaoMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                operadoraCartaoMenuActionPerformed(evt);
            }
        });
        cadastrosPreMenu.add(operadoraCartaoMenu);

        cadastrosMenu.add(cadastrosPreMenu);

        cadastrosBasicosMenu.setText("Cadastros básicos");

        setoresMenu.setText("Setores");
        setoresMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                setoresMenuActionPerformed(evt);
            }
        });
        cadastrosBasicosMenu.add(setoresMenu);

        colaboradoresMenu.setText("Colaboradores");
        colaboradoresMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                colaboradoresMenuActionPerformed(evt);
            }
        });
        cadastrosBasicosMenu.add(colaboradoresMenu);

        unidadesMenu.setText("Unidades");
        unidadesMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                unidadesMenuActionPerformed(evt);
            }
        });
        cadastrosBasicosMenu.add(unidadesMenu);

        cadastrosMenu.add(cadastrosBasicosMenu);

        selecionarEmpresa.setText("Selecionar empresa");
        selecionarEmpresa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                selecionarEmpresaActionPerformed(evt);
            }
        });
        cadastrosMenu.add(selecionarEmpresa);

        jMenuBar1.add(cadastrosMenu);

        relatoriosMenu.setText("Relatórios");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, entityManager, org.jdesktop.beansbinding.ELProperty.create("${empresa != null}"), relatoriosMenu, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        jMenuBar1.add(relatoriosMenu);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 609, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 359, Short.MAX_VALUE)
                .addContainerGap())
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void paisMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_paisMenuActionPerformed
        PaisView v = new PaisView();
        TelaButton.exibir(v, container, telasAbertas);
    }//GEN-LAST:event_paisMenuActionPerformed

    private void estadosMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_estadosMenuActionPerformed
        EstadoView v = new EstadoView();
        TelaButton.exibir(v, container, telasAbertas);
    }//GEN-LAST:event_estadosMenuActionPerformed

    private void cidadesMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cidadesMenuActionPerformed
        CidadesView v = new CidadesView();
        TelaButton.exibir(v, container, telasAbertas);
    }//GEN-LAST:event_cidadesMenuActionPerformed

    private void bancosMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bancosMenuActionPerformed
        TelaButton.exibir(new BancosView(), container, telasAbertas);
    }//GEN-LAST:event_bancosMenuActionPerformed

    private void agenciaBancoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_agenciaBancoActionPerformed
        TelaButton.exibir(new AgenciaBancoView(), container, telasAbertas);
    }//GEN-LAST:event_agenciaBancoActionPerformed

    private void cepMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cepMenuActionPerformed
        TelaButton.exibir(new CEPView(), container, telasAbertas);
    }//GEN-LAST:event_cepMenuActionPerformed

    private void indicesEconomicosMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_indicesEconomicosMenuActionPerformed
        TelaButton.exibir(new IndiceEconomicoView(), container, telasAbertas);
    }//GEN-LAST:event_indicesEconomicosMenuActionPerformed

    private void cfopMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cfopMenuActionPerformed
        TelaButton.exibir(new cfopView(), container, telasAbertas);
    }//GEN-LAST:event_cfopMenuActionPerformed

    private void operadoraCartaoMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_operadoraCartaoMenuActionPerformed
        TelaButton.exibir(new OperadoraCartaoView(), container, telasAbertas);
    }//GEN-LAST:event_operadoraCartaoMenuActionPerformed

    private void selecionarEmpresaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selecionarEmpresaActionPerformed
        entityManager.setEmpresa(null);
        telasAbertas.removeAll();
        container.removeAll();
        container.add("Empresas", new EmpresaView(container, entityManager));
        telasAbertas.validate();
        telasAbertas.repaint();
        container.validate();
        telasAbertas.repaint();
        System.gc();
    }//GEN-LAST:event_selecionarEmpresaActionPerformed

    private void setoresMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_setoresMenuActionPerformed
        TelaButton.exibir(new SetorView(), container, telasAbertas);
    }//GEN-LAST:event_setoresMenuActionPerformed

    private void colaboradoresMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_colaboradoresMenuActionPerformed
        TelaButton.exibir(new ColaboradorView(), container, telasAbertas);
    }//GEN-LAST:event_colaboradoresMenuActionPerformed

    private void unidadesMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_unidadesMenuActionPerformed
        TelaButton.exibir(new UnidadeView(), container, telasAbertas);
    }//GEN-LAST:event_unidadesMenuActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Inicial.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Inicial.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Inicial.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Inicial.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Inicial().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem agenciaBanco;
    private javax.swing.JMenuItem bancosMenu;
    private javax.swing.JMenu cadastrosBasicosMenu;
    private javax.swing.JMenu cadastrosMenu;
    private javax.swing.JMenu cadastrosPreMenu;
    private javax.swing.JMenuItem cepMenu;
    private javax.swing.JMenuItem cfopMenu;
    private javax.swing.JMenuItem cidadesMenu;
    private javax.swing.JMenuItem colaboradoresMenu;
    private javax.swing.JPanel container;
    private com.bs.persistencia.EntityManager entityManager;
    private javax.swing.JMenuItem estadosMenu;
    private javax.swing.JMenuItem indicesEconomicosMenu;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JMenuItem operadoraCartaoMenu;
    private javax.swing.JMenuItem paisMenu;
    private javax.swing.JMenu relatoriosMenu;
    private javax.swing.JMenuItem selecionarEmpresa;
    private javax.swing.JMenuItem setoresMenu;
    private javax.swing.JPanel telasAbertas;
    private javax.swing.JMenuItem unidadesMenu;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
}
